<?php

use Workerman\Protocols\Http;

error_reporting(1);
ini_set('display_errors', 'on');
Workerman\Protocols\Http::sessionStart();
$_SESSION["MOBILE_URL"] = "http://".$_SERVER["SERVER_NAME"].":".DEBUG_PORT;
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>我的生活</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <link rel="stylesheet" href="./css/sm.css">
    <link rel="stylesheet" href="./css/sm-extend.css">
    <link rel="stylesheet" href="./css/drag.css">
    <style>
        .content {
            color: #999;
        }
        .button.button-fill.button-big {
            line-height: 2.0rem;
            height: 2.0rem;
        }
        .list-block {
            margin: .75rem;
        }
        .content-block {
            margin: .75rem 0;
        }
        .signup a {
            color: #999;
        }
        .log_img{
            width: 100px;
            height: 100px;
            border-radius: 100px;
            clear: both;
            display: block;
            margin: auto;
        }
        .item-p{
            padding: 10px 15px;
        }

        .item-media{
            font-size: 15px;
            width: 20%;

        }
        .list-block .item-media + .item-inner{
            margin-left:0 !important;
        }
        .place-calss::-webkit-input-placeholder{
            font-size: 13px;

        }
    </style>
</head>
<body>

<div class="page-group">
    <!-- 你的html代码 -->
    <div class="page page-current" id="page-1581651169664">
        <header class="bar bar-nav" style="position: static;">
            <button class="button pull-left"  style="border:none;">
                <a href="#" id="return-login">返回</a>
            </button>
            <h1 class="title">注册</h1>
        </header>

        <div class="item-input" style="background: #ffffff;">
            <div class="page-login">
                <div class="list-block inset" style="margin-top: 0;">
                    <ul style="padding-top: 0.75rem;">
                        <li>
                            <div class="item-content">
                                <div class="item-media">工号：</div>
                                <div class="item-inner">
                                    <div class="item-input">
                                        <input type="number" name="code" class="place-calss"  placeholder="请输入工号">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-media">姓名：</div>
                                <div class="item-inner">
                                    <div class="item-input">
                                        <input type="text" class="place-calss" name="name" placeholder="请输入姓名">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-media"> 部门：</div>
                                <div class="item-inner">
                                    <div class="item-input">
                                        <input  type="text" id='picker'  class="place-calss"  placeholder="请选择部门">
                                    </div>
                                </div>
                            </div>
                        </li>

                        <li>
                            <div class="item-content">
                                <div class="item-media">手机号：</div>
                                <div class="item-inner">
                                    <div class="item-input">
                                        <input type="text" maxlength="11" class="place-calss"name="mobile" onkeyup="value=value.replace(/[^\d]/g,'') "  placeholder="请输入手机号">
                                    </div>
                                </div>
                            </div>
                        </li>

                        <li>
                            <div class="item-content">
                                <div class="item-media">密码：</div>
                                <div class="item-inner">
                                    <div class="item-input">
                                        <input type="password" maxlength="16" class="place-calss" name="pwd"  placeholder="请输入密码">
                                    </div>
                                </div>
                            </div>
                        </li>

                    </ul>
                </div>
                <div class="content-block">
                    <p><a class="button button-big button-fill external" id="register_button" href='#' data-transition='fade'>注册</a></p>
                    <p class='text-center signup' style="display: flex;justify-content: space-between;">

                    </p>

                </div>
            </div>
        </div>
    </div>








</div>

<script type="text/javascript" src="./js/zepto.min.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/sm.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/sm-extend.js" charset="utf-8"></script>
<script src="./js/drag.js"></script>
<script>
    $(function(){
        let departmentDataAjax = {action:"get_department"};
        let departmentData = "";
        let departmentId = "";
        $.ajax({
            type: "POST",
            url: "<?php echo $_SESSION["MOBILE_URL"];?>",
            dataType: "json",
            data:JSON.stringify(departmentDataAjax),
            success: function (result) {
                departmentData = result.rtval;
               let departmentArr =  result.rtval.map(item=>{return item.name});

                $("#picker").picker({
                    toolbarTemplate: '<header class="bar bar-nav">\
                <button class="button button-link pull-right close-picker">确定</button>\
                <h1 class="title">部门名称</h1>\
                </header>',
                    cols: [
                        {
                            textAlign: 'center',
                            values:departmentArr
                        }
                    ] ,
                    onClose:function (e) {
                        departmentData.map(item =>{
                            if (item.name == e.displayValue[0]){
                                departmentId = item.id;
                            }
                        })

                    }
                });
            },
            error:function(e){
                console.log(e);
            }
        });


        //退出注册页
        $(document).on('click','#return-login', function () {
            location.href = "./login.php";
        });

        //确定注册
        $(document).on("click" , "#register_button" , function () {
            if ($("input[name='code']")[0].value == "" ||
                $("input[name='name']")[0].value == "" ||
                $("input[name='mobile']")[0].value == ""||
                $("input[name='pwd']")[0].value == "" ||
                departmentId == ""){
                $.alert("全部必填")
                return
                }
              if ($("input[name='mobile']")[0].value.length < 11){
                  $.alert("手机号格式错误");
                  return;
              }


              let param = {
                  code:$("input[name='code']")[0].value ,
                  name: $("input[name='name']")[0].value,
                  department:departmentId ,
                  mobile:$("input[name='mobile']")[0].value ,
                  pwd: $("input[name='pwd']")[0].value
              };

            let data = {action:"set_user_account",param:param};
            $.ajax({
                type: "POST",
                url: "<?php echo $_SESSION["MOBILE_URL"];?>",
                dataType: "json",
                data:JSON.stringify(data),
                success: function (result) {
                    console.log(result)
                    if (result.errcode == 0){
                        $.alert(result.errmsg);
                        setTimeout(_=>{ location.href = "./login.php";} , 2000)

                    }
                },
                error:function(e){
                    console.log("error11");
                }
            });




            



        })





        $.init();
    })

</script>


<audio controls="controls" style="display: none;"></audio></body>
</html>